/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import controller.LoginControler;
import java.awt.Color;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import model.Base;
import net.miginfocom.swing.MigLayout;

/**
 *
 * @author Ira
 */
public class LoginView extends JPanel {
	//<editor-fold defaultstate="collapsed" desc="nom des composants">
	public static final String BTN_LOG = "log";
	public static final String BTN_QUIT = "quit";
	public static final String TXT_LOG = "login";
	public static final String TXT_PASS = "pass";
	public static final String LBL_ERROR = "error";
	//</editor-fold>
	
	private JLabel lblLogin = new JLabel("Identifiant");
	private JLabel lblPass = new JLabel("Mot de passe");
	private JButton btnLogin = new JButton("Login");
	private JButton btnQuit = new JButton("Quitter");
	private JTextField txtLogin = new JTextField(13);
	private JTextField txtPass = new JPasswordField(13);
	private JLabel lblInfo = new JLabel(" ");
	
	private LoginControler controler;
	private MainWindow mainWindow;
	
	public LoginView(Base model, MainWindow mainWindow) {
		this.mainWindow = mainWindow;
		this.btnQuit.setName(BTN_QUIT);
		this.btnLogin.setName(BTN_LOG);
		this.txtLogin.setName(TXT_LOG);
		this.txtPass.setName(TXT_PASS);
		this.lblInfo.setName(LBL_ERROR);
		this.lblInfo.setForeground(Color.red);
		
		this.controler = new LoginControler(model, this);
		this.setLayout(new MigLayout());
		this.add(this.lblLogin);
		this.add(this.txtLogin, "wrap");
		this.add(this.lblPass);
		this.add(this.txtPass, "wrap");
		
		JPanel pnlInfo = new JPanel();
		pnlInfo.add(this.lblInfo);
		this.add(pnlInfo, "span");
		
		this.add(this.btnQuit);
		this.add(this.btnLogin, "align right");
		
	
		this.txtLogin.addKeyListener(this.controler);
		this.txtPass.addKeyListener(this.controler);
		this.btnQuit.addActionListener(this.controler);	
		this.btnLogin.addActionListener(this.controler);
		this.btnLogin.addKeyListener(this.controler);
		this.btnQuit.addKeyListener(this.controler);
	}
	
	public void setInfo(String info) {
		this.lblInfo.setText(info);
	}
	
	public void accessContent(int accessLevel) {
		this.mainWindow.accessGranted(accessLevel);
	}
	
	public String getPseudo() {
		return this.txtLogin.getText();
	}
	
	public String getPass() {
		return this.txtPass.getText();
	}
}
